<template>
	<view class="page page-fill">
		<u-navbar :is-back="true" :title="title" title-color="white" :background="background"></u-navbar>
		<form @submit="formSubmitBirthday">
			
			<view class="page-block" style="margin-top: 20upx;">
				<input
					type="text"
					name="contact"
					:value="globalUser.city" 
					class="input"
					placeholder="请输入微信号"
					placeholder-class="graywords"
					maxlength="20"
					/>
			</view>
			
			<button type="primary" form-type="submit" class="submitBtn">提交</button>
			
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:"联系方式",
				background:{
					backgroundImage:'linear-gradient(to top, #ffd655 0%, #fda085 100%)',
				},
				globalUser: {}
			}
		},
		onLoad() {
			var me = this;
			var globalUser = me.getGlobalUser("globalUser");
			me.globalUser = globalUser;
			var userSkey = me.globalUser.user.skey;
			me.userSkey = userSkey;
		},
		methods: {
			formSubmitBirthday(e) {
				var me = this;
				var contact = e.detail.value.contact;
				uni.request({
						url: me.baseUrl + "/mini_program/user-wechat/editUser/" + me.userSkey,
						data: {
							"city": contact
						},
						method: "POST",
						success(res) {
							var resData = res.data;
							console.log(resData);
							if (resData.code == 20000) {
								// 获得最新的用户数据
								var userInfo = resData.data;
								console.log(userInfo);
								uni.setStorageSync("globalUser", userInfo);
								uni.navigateBack({
									delta: 2
								})
							} else if (resData.code == 502 || resData.code == 500) {
								uni.showToast({
									title: res.data.msg,
									image: "../../static/icos/error.png",
									duration: 2000
								})
							}
						},
						complete() {
							uni.hideLoading();
						}
					})
				}
			
		}
	}
</script>

<style>
	/* 页面铺满屏幕 */
	.page-fill {
		width:100%;
		height: 100%;
		position: absolute;
	}
	
	.birth-input {
		background-color: white;
		height: 80upx;
		line-height: 40upx;
		padding-left: 20upx;
	}
	
	.birthday {
		background-color: white;
		height: 80upx;
		padding-left: 20upx;
		padding-top: 30upx;
	}
	
	.submitBtn {
		width: 95%;
		margin-top: 40upx;
	}
</style>
